1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| #include<cstdio> #include<cstring> #define re register typedef long long ll; const int MAXn = 2e5 + 5e4; const int MAXmat = 4; const int MOD = 998244353;
template <class T> inline void read(T &a) { register char c;while (c = getchar(), (c < '0' || c > '9') && c != '-');register bool f = c == '-';register T x = f ? 0 : c - '0';while (c = getchar(), c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48);}a = f ? -x : x; }
struct Mat { int mat[MAXmat][MAXmat]; Mat() { memset(mat, 0, sizeof(mat)); } Mat(int a[MAXmat][MAXmat]) { for (re int i = 0; i < MAXmat; ++i) { for (re int j = 0; j < MAXmat; ++j) { mat[i][j] = a[i][j]; } } } inline void operator=(Mat x) { for (re int i = 0; i < MAXmat; ++i) { for (re int j = 0; j < MAXmat; ++j) { mat[i][j] = x.mat[i][j]; } } } inline Mat operator+(Mat x) { Mat ans; for (int i = 0; i < MAXmat; ++i) { for (int j = 0; j < MAXmat; ++j) { ans.mat[i][j] = ((ll)mat[i][j] + x.mat[i][j]) % MOD; } } return ans; } inline Mat operator*(Mat x) { Mat ans; for (re int i = 0; i < MAXmat; ++i) { for (re int k = 0; k < MAXmat; ++k) { int a = mat[i][k]; for (re int j = 0; j < MAXmat; ++j) { ans.mat[i][j] = ((ll)a * x.mat[k][j] + ans.mat[i][j]) % MOD; } } } return ans; } inline Mat operator^(int x) { Mat ans, base; for (re int i = 0; i < MAXmat; ++i) { ans.mat[i][i] = 1; } for (re int i = 0; i < MAXmat; ++i) { for (re int j = 0; j < MAXmat; ++j) { base.mat[i][j] = mat[i][j]; } } while (x) { if (x & 1) { ans = ans * base; } base = base * base; x >>= 1; } return ans; } }; int I_[MAXmat][MAXmat] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, }; Mat I(I_);
int le[MAXn * 4 + 10], ri[MAXn * 4 + 10]; Mat sum[MAXn * 4 + 10], mul[MAXn * 4 + 10]; inline void pushup(int id) { sum[id] = (sum[id << 1] + sum[(id << 1) + 1]); } inline void pushdown(int id) { sum[id << 1] = (sum[id << 1] * mul[id]); sum[(id << 1) + 1] = (sum[(id << 1) + 1] * mul[id]); mul[id << 1] = (mul[id << 1] * mul[id]); mul[(id << 1) + 1] = (mul[(id << 1) + 1] * mul[id]); mul[id] = I; } void BuildUseArr(int id, int l, int r, Mat *a) { le[id] = l; ri[id] = r; mul[id] = I; if (l == r) { sum[id] = a[l]; } else { int mid = (l + r) >> 1; BuildUseArr(id << 1, l, mid, a); BuildUseArr((id << 1) + 1, mid + 1, r, a); pushup(id); } } void Mul(int id, int l, int r, Mat k) { if (le[id] >= l && ri[id] <= r) { mul[id] = (mul[id] * k); sum[id] = (sum[id] * k); } else { pushdown(id); int mid = (le[id] + ri[id]) >> 1; if (l <= mid) Mul(id << 1, l, r, k); if (r > mid) Mul((id << 1) + 1, l, r, k); pushup(id); } } Mat Sum(int id, int l, int r) { if (le[id] >= l && ri[id] <= r) { return sum[id]; } else { pushdown(id); int mid = (le[id] + ri[id]) >> 1; Mat ans; if (l <= mid) ans = Sum(id << 1, l, r); if (r > mid) ans = (ans + Sum((id << 1) + 1, l, r)); return ans; } }
int n, m; Mat a[MAXn + 10], G; int A_[MAXmat][MAXmat] = { {1, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, }; Mat A(A_); int B_[MAXmat][MAXmat] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {0, 0, 0, 1}, }; Mat B(B_); int C_[MAXmat][MAXmat] = { {1, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, }; Mat C(C_); int D_[MAXmat][MAXmat] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, }; Mat D(D_); int E_[MAXmat][MAXmat] = { {1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, }; Mat E(E_); int F_[MAXmat][MAXmat] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 1}, }; Mat F(F_); signed main() { read(n); for (re int i = 1; i <= n; ++i) { read(a[i].mat[0][0]), read(a[i].mat[0][1]), read(a[i].mat[0][2]); a[i].mat[0][3] = 1; } BuildUseArr(1, 1, n, a); read(m); for (re int i = 1, opt, l, r, v; i <= m; ++i) { read(opt); switch (opt) { case 1: read(l), read(r); Mul(1, l, r, A); break; case 2: read(l), read(r); Mul(1, l, r, B); break; case 3: read(l), read(r); Mul(1, l, r, C); break; case 4: read(l), read(r), read(v); D.mat[3][0] = v; Mul(1, l, r, D); break; case 5: read(l), read(r), read(v); E.mat[1][1] = v; Mul(1, l, r, E); break; case 6: read(l), read(r), read(v); F.mat[3][2] = v; Mul(1, l, r, F); break; case 7: read(l), read(r); G = Sum(1, l, r); printf("%d %d %d\n", G.mat[0][0], G.mat[0][1], G.mat[0][2]); break; } } }
|